home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0411.ZIP
/
PRINT.C
< prev
next >
Wrap
Text File
|
1985-09-23
|
13KB
|
428 lines
/******************************************************************************/
/* */
/* Program to print a file */
/* */
/******************************************************************************/
#include "stdio.h"
main(argc,argv)
int argc;
char *argv[];
{
char outname[64],
headstr[241],
pagestr[4],
monstr[37],
prntdate[10],
sysdate[9];
int outfile,
infile,
infilen,
i,
j,
c,
cntr,
length,
width,
left,
right,
top,
bottom,
condense,
heading,
rhspace,
lhspace,
datelen,
pageno,
pgnolen,
prntchrz,
prntlinz,
dataarea,
finished,
offset;
long value;
/**************************************************************************/
/* */
/* If information requested, display syntax */
/* */
/**************************************************************************/
if ((argc == 1) || (argv[1][0] == '?'))
{
puts("\n");
puts("PRINT <printfile> [/C] [/F<outfile>] [/W<nnn>] [/P<nnn>]\n");
puts(" [/T<nnn>] [/B<nnn>] [/L<nnn>] [/R<nnn>] [/H]\n\n");
puts("where printfile filespec for the file to be printed.\n");
puts(" Default: None\n\n");
puts(" /C condensed print mode.\n");
puts(" Default: mode at time of invocation.\n\n");
puts(" /Foutfile filespec for the output file when\n");
puts(" output to file is desired.\n");
puts(" Default: PRN\n\n");
puts(" /Wnnn page width.\n");
puts(" Default: 132\n");
puts(" Minimum: 2+L+R\n");
puts(" Maximum: 240\n\n");
puts(" /Pnnn page length.\n");
puts(" Default: 66\n");
puts(" Minimum: 2+T+B\n");
puts(" Maximum: 999\n");
puts("\n");
puts("Press any key to continue ... ");
c = '\0';
while (c == '\0')
{
c = ci();
}
for(cntr=0;cntr<0x1e;cntr++)
{
co('\b');
}
puts(" /Tnnn no of blank lines at top of page.\n");
puts(" Default: 5\n");
puts(" Minimum: 0\n");
puts(" Maximum: P-B-2\n\n");
puts(" /Bnnn no of blank lines at bottom of page.\n");
puts(" Default: 5\n");
puts(" Minimum: 0\n");
puts(" Maximum: P-T-2\n\n");
puts(" /Lnnn no of characters for left margin.\n");
puts(" Default: 5\n");
puts(" Minimum: 0\n");
puts(" Maximum: W-R-1\n\n");
puts(" /Rnnn no of characters for right margin.\n");
puts(" Default: 0\n");
puts(" Minimum: 0\n");
puts(" Maximum: W-L-1\n\n");
puts(" /H don't print heading.\n");
puts(" Default: print heading.\n");
exit(0);
}
/**************************************************************************/
/* */
/* Display version information if requested */
/* */
/**************************************************************************/
if (argv[1][0] == '#')
{
puts("\n");
puts("Program: PRINT\n");
puts("Author : Peter Townsend\n");
puts("Date : 21Sep85\n");
puts("Time : 15:08\n");
puts("Version: 1.0\n");
exit(0);
}
/**************************************************************************/
/* */
/* Initialise */
/* */
/**************************************************************************/
top = 5;
bottom = 5;
left = 5;
right = 0;
width = 132;
length = 66;
outfile = -1;
condense = 0;
heading = 0;
headstr[0] = '\0';
prntchrz = 0;
pageno = 0;
/**************************************************************************/
/* */
/* Check for wildcard characters in filename */
/* */
/**************************************************************************/
for(cntr=0;cntr<strlen(argv[1]);cntr++)
{
if ((argv[1][cntr] == '*') || (argv[1][cntr] == '?'))
{
puts("\n");
puts("Sorry ... wildcards not catered for.\n");
exit(0);
}
}
/**************************************************************************/
/* */
/* Attempt to open file to be printed */
/* */
/**************************************************************************/
if ((infile = open(argv[1],0)) == -1)
{
printf("\nCannot access file %s\n",argv[1]);
exit(1);
}
fclose(infile);
dissect(value,i,j,bottom,condense,heading,left,length,right,width,argv,outname,argc,outfile,top);
/**************************************************************************/
/* */
/* Check validity of page parameters */
/* */
/**************************************************************************/
if ((top + bottom + heading) >= length)
{
puts("\n");
printf("TOP = %3d\n",top);
printf("BOTTOM = %3d\n",bottom);
printf("HEADING = %3d\n",heading);
puts("--------------\n");
printf("LENGTH = %3d\n",length);
puts("\n");
puts("You have not left any lines to allow printing of data.\n");
exit(0);
}
if ((right + left) >= width)
{
puts("\n");
printf("LEFT = %3d\n",left);
printf("RIGHT = %3d\n",right);
puts("--------------\n");
printf("WIDTH = %3d\n",width);
puts("\n");
puts("You have not left any positions to print the data.\n");
exit(0);
}
if (width > 0xf0)
{
puts("\n");
puts("Maximum value for width = 240\n");
exit(0);
}
if (length > 0x3e7)
{
puts("\n");
puts("Maximum value for length = 999\n");
exit(0);
}
/**************************************************************************/
/* */
/* Open output file */
/* */
/**************************************************************************/
if (outfile == -1)
{
if ((outfile = open("prn",1)) == -1)
{
if ((outfile = creat("prn")) == -1)
{
puts("\n");
puts("Cannot access printer\n");
exit(1);
}
}
}
else
{
if ((outfile = open(outname,1)) == -1)
{
if ((outfile = creat(outname)) == -1)
{
puts("\n");
printf("Cannot access file %s\n",outname);
exit(1);
}
}
}
/**************************************************************************/
/* */
/* If necessary, create heading string */
/* */
/**************************************************************************/
if (heading)
{
/**********************************************************************/
/* */
/* Create heading date */
/* */
/**********************************************************************/
strcpy(sysdate,dates());
prntdate[0] = sysdate[3];
prntdate[1] = sysdate[4];
prntdate[2] = 0x20;
strcpy(monstr,"JanFebMarAprMayJunJulAugSepOctNovDec");
offset = (((sysdate[0] - '0') * 10) + (sysdate[1] - '0'));
offset = ((offset -1) * 3);
for(i = 3; i < 6; i++)
{
prntdate[i] = monstr[i+offset];
}
prntdate[6] = 0x20;
prntdate[7] = sysdate[6];
prntdate[8] = sysdate[7];
prntdate[9] = '\0';
/**********************************************************************/
/* */
/* Calculate spacing either side of file name */
/* */
/**********************************************************************/
infilen = strlen(argv[1]);
datelen = 0x9;
pgnolen = 0x9;
if ((infilen + datelen + pgnolen + 2) >= width)
{
lhspace = width - (ceil(infilen/2) + datelen);
rhspace = width - (ceil(infilen/2) + pgnolen);
if ((ceil(infilen/2) *2) != infilen)
{
rhspace = rhspace + 1;
}
}
else
{
lhspace = 1;
rhspace = 1;
}
/**********************************************************************/
/* */
/* Initialise heading string */
/* */
/**********************************************************************/
sprintf(headstr,"%s%s%s%sPage: ",prntdate,lhspace,argv[1],rhspace);
/**********************************************************************/
/* */
/* Check for room to print heading and some data */
/* */
/**********************************************************************/
dataarea = width - (left + right);
dataarea = dataarea * (length - (top + bottom));
if ((strlen(headstr) + 3) > dataarea)
{
puts("\n");
puts("Insufficient space to print heading and data\n");
puts("within given parameters.\n");
exit(1);
}
}
/**************************************************************************/
/* */
/* Attempt to open file to be printed */
/* */
/**************************************************************************/
if ((infile = open(argv[1],0)) == -1)
{
printf("\nCannot access file %s\n",argv[1]);
exit(1);
}
/**************************************************************************/
/* */
/* Print top margin lines if any */
/* */
/**************************************************************************/
for(i = 0; i < top; i++)
{
putc('\n',outfile);
}
prntlinz = length + 1;
/**************************************************************************/
/* */
/* Set condensed mode if desired */
/* */
/**************************************************************************/
finished = ((c = fgetc(infile)) == EOF);
if (!finished)
{
if (condense)
{
putc(0x15,outfile);
}
}
/**************************************************************************/
/* */
/* Print */
/* */
/**************************************************************************/
puts("\n");
while (!finished)
{
/**********************************************************************/
/* */
/* Check for end of line operations */
/* */
/**********************************************************************/
if ((prntchrz >= width) || (c == 0xa))
{
if (prntchrz >= width)
{
putc(0xd,outfile);
putc(0xa,outfile);
}
for(i = 0; i < left; i++)
{
putc(' ',outfile);
}
prntchrz = left;
prntlinz++;
}
/**********************************************************************/
/* */
/* Check for end of page operations */
/* */
/**********************************************************************/
if (prntlinz >= length)
{
/******************************************************************/
/* */
/* If necessary, print heading */
/* */
/******************************************************************/
if (heading)
{
pageno++;
sprintf(pagestr,"%3d",pageno);
fprintf(outfile,"%s%s\n",headstr,pagestr);
}
/******************************************************************/
/* */
/* Print bottom, top, and left margins */
/* */
/******************************************************************/
for(i = 0; i < (top + bottom); i++)
{
putc('\n',outfile);
}
for(i = 0; i < left; i++)
{
putc(' ',outfile);
}
prntchrz = left;
prntlinz = top;
}
/**********************************************************************/
/* */
/* Print the character and get another */
/* */
/**********************************************************************/
putc(c,outfile);
if ((c == 0xd) || (c == 0xa))
{
if (c == 0xa)
{
prntchrz = 0;
}
}
else
{
if (c == 0x9)
{
prntchrz = prntchrz + 3;
}
prntchrz++;
}
finished = ((c = fgetc(infile)) == EOF);
}
/**************************************************************************/
/* */
/* Put a formfeed in the output device */
/* */
/**************************************************************************/
putc(0xc,outfile);
/**************************************************************************/
/* */
/* Tidy-up, close files */
/* */
/**************************************************************************/
fclose(infile);
fclose(outfile);
exit(0);
}